//Main.java

import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;

import java.io.*;

import java.util.ArrayList;

import com.alibaba.fastjson.JSONObject;
import com.peter.bean.Project;
import com.peter.utils.Operator;
import com.peter.utils.RedisOperatorUtil;

import java.util.concurrent.TimeUnit;

public class Demo2 {
    public static double similarity(ArrayList va, ArrayList vb) {
        if (va.size() > vb.size()) {
            int temp = va.size() - vb.size();
            for (int i = 0; i < temp; i++) {
                vb.add(0);
            }
        } else if (va.size() < vb.size()) {
            int temp = vb.size() - va.size();
            for (int i = 0; i < temp; i++) {
                va.add(0);
            }
        }

        int size = va.size();
        double simVal = 0;


        double num = 0;
        double den = 1;
        double powa_sum = 0;
        double powb_sum = 0;
        for (int i = 0; i < size; i++) {
            double a = Double.parseDouble(va.get(i).toString());
            double b = Double.parseDouble(vb.get(i).toString());

            num = num + a * b;
            powa_sum = powa_sum + (double) Math.pow(a, 2);
            powb_sum = powb_sum + (double) Math.pow(b, 2);
        }
        double sqrta = (double) Math.sqrt(powa_sum);
        double sqrtb = (double) Math.sqrt(powb_sum);
        den = sqrta * sqrtb;

        simVal = num / den;

        return simVal;
    }


    public static float levenshtein(String str1,String str2) {
        int n=6;
        float sum=0;
        int count=0;
        int step=3;
        for(int sp=1;sp<=n;sp+=step) {
            int len1 = (str1.length()/n)*sp;
            int len2 = (str2.length()/n)*sp;

            int[][] dif = new int[len1 + 1][len2 + 1];

            for (int a = 0; a <= len1; a++) {
                dif[a][0] = a;
            }
            for (int a = 0; a <= len2; a++) {
                dif[0][a] = a;
            }

            int temp;
            for (int i = (str1.length()/n)*(sp-1)+1; i <= len1; i++) {
                for (int j = (str1.length()/n)*(sp-1)+1; j <= len2; j++) {
                    if (str1.charAt(i - 1) == str2.charAt(j - 1)) {
                        temp = 0;
                    } else {
                        temp = 1;
                    }

                    dif[i][j] = min(dif[i - 1][j - 1] + temp, dif[i][j - 1] + 1,
                            dif[i - 1][j] + 1);
                }
            }
            //System.out.println("块\""+str1+"\"与\""+str2+"\"的比较");

            //System.out.println("dist：" + dif[len1][len2]);

            float similarity = 1 - (float) dif[len1][len2] / Math.max(str1.length()/n, str2.length()/n);
            //System.out.println("similiar："+similarity+"\n");
            sum+=similarity;
            count++;
            System.gc();
            Runtime.getRuntime().gc();
        }

        System.out.println("similiar："+sum/count+"\n");
        return sum/count;
    }


    //得到最小值
    private static int min(int... is) {
        int min = Integer.MAX_VALUE;
        for (int i : is) {
            if (min > i) {
                min = i;
            }
        }
        return min;
    }

    public static  String readFromTextFile(String pathname) throws IOException{
        String code="";
        File filename = new File(pathname);
        InputStreamReader reader = new InputStreamReader(new FileInputStream(filename));
        BufferedReader br = new BufferedReader(reader);
        String line = "";
        line = br.readLine();
        while(line != null) {
            code+=line+"\n";
            line = br.readLine();
        }
        return code;
    }

    public static void saveAsFileWriter(String content , String filePath) {
        FileWriter fwriter = null;
        try {
            // true is append,false is cover
            fwriter = new FileWriter(filePath, false);
            fwriter.write(content);
        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            try {
                fwriter.flush();
                fwriter.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }

    public static void convertCppToAst(String loadPath,String savePath) throws IOException {
        System.out.println("convert\t"+loadPath+"\tto\t"+savePath);
        String code=readFromTextFile(loadPath);

        ANTLRInputStream input = new ANTLRInputStream(code);
        CPP14Lexer lexer = new CPP14Lexer(input);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        CPP14Parser parser = new CPP14Parser(tokens);
        CPP14Parser.TranslationunitContext tree = parser.translationunit();

        CPP14BaseVisitorBinary loader = new CPP14BaseVisitorBinary();
        //CPP14BaseVisitor loader = new CPP14BaseVisitor();
        loader.visit(tree);
        System.out.println("encode_string:"+loader.encode_str);
        saveAsFileWriter(loader.encode_str,savePath);
    }



    public  static String getCppName(String path)
    {
        String[] sp ;
        sp=path.split("\\\\");
        String cpp=sp[sp.length-1];
        return cpp.split("\\.")[0];
    }
    public static ArrayList<String> getLibFiles(String libPath)
    {
        ArrayList<String> files=new ArrayList<>();
        File file = new File(libPath);
        File[] gp_fs = file.listFiles();
        for(File f:gp_fs)
        {
            System.out.println("——"+f);
            if(f.isDirectory())
            {
                File src=new File(f.toString()+"\\src");
                File[] srcs = src.listFiles();
                for(File s:srcs)
                {
                    if(s.getPath().endsWith(".cpp")) {
                        System.out.println("—— ——" + s);
                        files.add(s.getPath());
                    }
                }
            }
        }
        return files;
    }
    public static ArrayList<String> getFetchFiles(String fetchPath)
    {
        ArrayList<String> files=new ArrayList<>();
        File file = new File(fetchPath);
        File[] gp_fs = file.listFiles();
        for(File f:gp_fs)
        {
             if(f.getPath().endsWith(".cpp")) {
                 System.out.println("—— ——" + f);
                 files.add(f.getPath());
             }
        }
        return files;
    }
    public static void compareGitProject(String gitPath,String libPath) throws IOException
    {

        String gp_path=libPath+"\\global_planner";
        ArrayList<String> gp_files=getLibFiles(gp_path);
        String slam_path=libPath+"\\slam";
        ArrayList<String> slam_files=getLibFiles(slam_path);

        File file = new File(gitPath);
        File[] git_fs = file.listFiles();
        for(File f:git_fs)
        {
            //System.out.println("——"+f);
            if(f.isDirectory())
            {

                File src=new File(f.toString()+"\\src");
                File[] srcs = src.listFiles();

                float gp_sim = 0;
                float slam_sim=0;

                int filecount=0;
                if(srcs==null)
                {
                    continue;
                }
                for(File s:srcs)
                {
                    float gp_similarity = 0;
                    float slam_similarity=0;
                    int gp_filecount=0;
                    int slam_filecount=0;
                    if(s.getPath().endsWith(".cpp")) {
                        filecount++;
                        System.out.println("—— ——" + s);
                        for (String gp_file : gp_files) {
                            float sim = compareSingleCpp(gp_file, s.getPath());
                            gp_similarity += sim;
                            System.gc();
                            Runtime.getRuntime().gc();
                            gp_filecount++;
                            //System.out.println(sim);
                        }

                        for (String slam_file :slam_files) {
                            float sim = compareSingleCpp(slam_file, s.getPath());
                            slam_similarity += sim;
                            System.gc();
                            Runtime.getRuntime().gc();
                            slam_filecount++;
                        }
                        gp_sim+=gp_similarity/gp_filecount;
                        slam_sim+=slam_similarity/gp_filecount;
                        System.out.println("File:"+s.getPath());
                        System.out.println("global_planner_similarity:"+gp_similarity/gp_filecount);
                        System.out.println("slam_similarity:"+slam_similarity/slam_filecount);
                    }

                }
                System.out.println("~Project:"+f.getPath());
                System.out.println("~global_planner_similarity:"+gp_sim/filecount);
                System.out.println("~slam_similarity:"+slam_sim/filecount);
            }
        }
    }
    public static void makeAst(String path) throws IOException {
        File file = new File(path);
        File[] fs = file.listFiles();
        for(File f:fs)
        {
            System.out.println("——"+f);
            System.out.println("Convert Cpp to Ast");
            convertCppToAst(f.toString(),path+"\\"+getCppName(f.toString())+"_ast.txt");

        }
    }

    public static Tree MergeCppFuncs(String loadPath) throws IOException {
        TreeProcessor tp=new TreeProcessor();
        String code=readFromTextFile(loadPath);

        ANTLRInputStream input = new ANTLRInputStream(code);
        CPP14Lexer lexer = new CPP14Lexer(input);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        CPP14Parser parser = new CPP14Parser(tokens);
        CPP14Parser.TranslationunitContext tree = parser.translationunit();

        tree.removeLastChild();
        //System.out.println(tree.getText());
        //visitorTree(tree4,parser4);
        Tree myTree=new Tree(tp.getRuleName(tree,parser));
        tp.convertTree(tree,parser,myTree);

        ArrayList<Tree> funclist=new ArrayList<>();
        tp.getFunctionDefinition(myTree,funclist);


        ArrayList<String> funcNameList=new ArrayList<>();
        for(Tree Func:funclist){
            StringBuffer sb=new StringBuffer();
            tp.getFunctionName(Func,sb);
            //System.out.println("function name:"+sb.toString().strip());
            funcNameList.add(sb.toString().strip());
        }
        /*get param from every  function,make it a matrix*/
        ArrayList<ArrayList<String>> ParamList=new ArrayList<>();
        for(Tree Func:funclist){
            //System.out.print("function params:");
            ArrayList<String> param=new ArrayList<>();
            tp.getFuncParams(Func,param);
            //for(String p:param) System.out.print(p+"  ");
            //System.out.println();
            ParamList.add(param);
        }

        /*get function statementseq Tree*/
        ArrayList<Tree> funcBodyList=new ArrayList<>();
        for(Tree Func:funclist){
            funcBodyList.add(tp.getFuncStatementseq(Func));
        }
        for(Tree Func:funcBodyList){
            //System.out.println(Func.getRootData());
        }

        /*get return statement ,change return to (***) <tree>*/
        ArrayList<Tree> returnTreeList=new ArrayList<>();
        for(Tree Func:funclist){
            Tree ret=tp.getReturnStatementTree(Func);
            returnTreeList.add(ret);
        }




        /*get call function statement in a code*/
        ArrayList<Tree> CallFuncList=new ArrayList<>();
        tp.getCallFunc(myTree,CallFuncList);

        /*get param from every called function,make it a matrix*/
        ArrayList<ArrayList<String>> calledParamList=new ArrayList<>();
        for(Tree callFunc:CallFuncList){
            ArrayList<String> param=tp.getCalledParams(callFunc);
            calledParamList.add(param);
        }

        tp.mergeFunc(myTree,funcNameList,returnTreeList,ParamList,calledParamList,funcBodyList);

        //System.out.println("printing code...");
        //tp.printCode(myTree);
        //System.out.println("\nprinting code over.");

        return myTree;

    }
    public static  void compareAfterMerge(String fetch_path,String libPath) throws IOException {
        String gp_path=libPath+"\\global_planner";
        ArrayList<String> gp_files=getLibFiles(gp_path);
        String slam_path=libPath+"\\slam";
        ArrayList<String> slam_files=getLibFiles(slam_path);
        TreeProcessor tp=new TreeProcessor();
        ArrayList<String> fetch_files=getFetchFiles(fetch_path);


        //
        float gp_similarity = 0;
        float slam_similarity=0;
        int gp_filecount=0;
        int slam_filecount=0;
        for(String fetch:fetch_files)
        {

            Tree tree1;
            tree1=MergeCppFuncs(fetch);
            StringBuffer s1=new StringBuffer();
            StringBuffer lessEncode1=tp.lessEncode(tree1,s1);
            for(String gp_file:gp_files)
            {
                String code=readFromTextFile(gp_file);
                Tree tree2=getMyTreeFromCode(code);
                StringBuffer s2=new StringBuffer();
                StringBuffer lessEncode2=tp.lessEncode(tree2,s2);
                System.out.println("compare file:\t"+fetch+"\tand\t"+gp_file);
                float sim=levenshtein(lessEncode1.toString(),lessEncode2.toString());
                gp_similarity+=sim;
                System.gc();
                Runtime.getRuntime().gc();
                gp_filecount++;
            }
            for(String slam_file:slam_files)
            {
                String code=readFromTextFile(slam_file);
                Tree tree2=getMyTreeFromCode(code);
                StringBuffer s2=new StringBuffer();
                StringBuffer lessEncode2=tp.lessEncode(tree2,s2);
                System.out.println("compare file:\t"+fetch+"\tand\t"+slam_file);
                float sim=levenshtein(lessEncode1.toString(),lessEncode2.toString());
                slam_similarity+=sim;
                System.gc();
                Runtime.getRuntime().gc();
                slam_filecount++;
            }
            System.gc();
            Runtime.getRuntime().gc();
            System.out.println("global_planner_similarity:"+gp_similarity/gp_filecount);
            System.out.println("slam_similarity:"+slam_similarity/slam_filecount);

        }

    }
    public static  void compareWithoutMerge(String fetch_path,String libPath) throws IOException {
        String gp_path=libPath+"\\global_planner";
        ArrayList<String> gp_files=getLibFiles(gp_path);
        String slam_path=libPath+"\\slam";
        ArrayList<String> slam_files=getLibFiles(slam_path);
        TreeProcessor tp=new TreeProcessor();
        ArrayList<String> fetch_files=getFetchFiles(fetch_path);


        //
        float gp_similarity = 0;
        float slam_similarity=0;
        int gp_filecount=0;
        int slam_filecount=0;
        for(String fetch:fetch_files)
        {


            String code1=readFromTextFile(fetch);
            Tree tree1=getMyTreeFromCode(code1);
            StringBuffer s1=new StringBuffer();
            StringBuffer lessEncode1=tp.lessEncode(tree1,s1);
            for(String gp_file:gp_files)
            {
                String code=readFromTextFile(gp_file);
                Tree tree2=getMyTreeFromCode(code);
                StringBuffer s2=new StringBuffer();
                StringBuffer lessEncode2=tp.lessEncode(tree2,s2);
                System.out.println("compare file:\t"+fetch+"\tand\t"+gp_file);
                float sim=levenshtein(lessEncode1.toString(),lessEncode2.toString());
                gp_similarity+=sim;
                System.gc();
                Runtime.getRuntime().gc();
                gp_filecount++;
            }
            for(String slam_file:slam_files)
            {
                String code=readFromTextFile(slam_file);
                Tree tree2=getMyTreeFromCode(code);
                StringBuffer s2=new StringBuffer();
                StringBuffer lessEncode2=tp.lessEncode(tree2,s2);
                System.out.println("compare file:\t"+fetch+"\tand\t"+slam_file);
                float sim=levenshtein(lessEncode1.toString(),lessEncode2.toString());
                slam_similarity+=sim;
                System.gc();
                Runtime.getRuntime().gc();
                slam_filecount++;
            }
            System.gc();
            Runtime.getRuntime().gc();
            System.out.println("~File:"+fetch);
            System.out.println("~global_planner_similarity:"+gp_similarity/gp_filecount);
            System.out.println("~slam_similarity:"+slam_similarity/slam_filecount);
            System.out.println();

        }

    }
    public static Tree getMyTreeFromCode(String code)
    {
        TreeProcessor tp=new TreeProcessor();
        ANTLRInputStream input = new ANTLRInputStream(code);
        CPP14Lexer lexer = new CPP14Lexer(input);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        CPP14Parser parser = new CPP14Parser(tokens);
        CPP14Parser.TranslationunitContext tree = parser.translationunit();

        tree.removeLastChild();
        //System.out.println(tree.getText());
        //visitorTree(tree4,parser4);
        Tree myTree=new Tree(tp.getRuleName(tree,parser));
        tp.convertTree(tree,parser,myTree);
        return myTree;
    }
    public static  float compareSingleCpp(String path1,String path2) throws IOException {
        TreeProcessor tp=new TreeProcessor();

        //
        String libFile=readFromTextFile(path1);
        String gitFile=readFromTextFile(path2);

        Tree tree1;
        tree1=getMyTreeFromCode(libFile);
        Tree tree2;
        tree2=getMyTreeFromCode(gitFile);

        StringBuffer s1=new StringBuffer();
        StringBuffer lessEncode1=tp.lessEncode(tree1,s1);
        StringBuffer s2=new StringBuffer();
        StringBuffer lessEncode2=tp.lessEncode(tree2,s2);


        System.out.println("compare file:\t"+path1+"\tand\t"+path2);
        float sim=levenshtein(lessEncode1.toString(),lessEncode2.toString());
        //System.out.println(sim);
        return sim;
    }


    public static void modifyInterface(Tree myTree,ArrayList<String> rep)
    {
        TreeProcessor tp=new TreeProcessor();
        //get all declared function
        ArrayList<Tree> funclist=new ArrayList<>();
        tp.getFunctionDefinition(myTree,funclist);


        //get function names
        ArrayList<String> funcNameList=new ArrayList<>();
        for(Tree Func:funclist){
            StringBuffer sb=new StringBuffer();
            tp.getFunctionName(Func,sb);
            funcNameList.add(sb.toString().strip());
        }
        //get param from every  function,make it a matrix
        ArrayList<ArrayList<String>> ParamList=new ArrayList<>();
        for(Tree Func:funclist){
            System.out.print("function params:");
            ArrayList<String> param=new ArrayList<>();
            tp.getFuncParams(Func,param);
            for(String p:param) System.out.print(p+"  ");
            System.out.println();
            ParamList.add(param);
        }

        //get function statementseq Tree
        ArrayList<Tree> funcBodyList=new ArrayList<>();
        for(Tree Func:funclist){
            funcBodyList.add(tp.getFuncStatementseq(Func));
        }
        for(Tree Func:funcBodyList){
            System.out.println(Func.getRootData());
        }

        System.out.println();
        System.out.println("origin");
        tp.printCode(funclist.get(0));
        tp.replaceParam(funclist.get(0),ParamList.get(0),rep);
        System.out.println();
        System.out.println("after modify");
        tp.printCode(funclist.get(0));
    }

    public static void publishProject()
    {
        System.setProperty("com.mchange.v2.log.MLog", "com.mchange.v2.log.FallbackMLog");
        System.setProperty("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL", "WARNING");

        //初始化操作redis的工具类
        RedisOperatorUtil redisUtil = new RedisOperatorUtil("116.62.140.19", "growningai");
        //初始化操作数据库的工具类
        Operator<Project> projectOperator = new Operator<>("projectService");
        String result=null;
        int i=1;
        //从redis获取项目的信息
        while ((result= redisUtil.subscribe())!=null){
            //解析json成对象
            Project project = JSONObject.parseObject(result, Project.class);

            //分析项目
            try {
                TimeUnit.SECONDS.sleep(3);
                //设置剩余的属性值
                project.setName("project"+(i++));
                project.setType("slam");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            //保存项目到数据库
//            projectOperator.save(project);
            System.out.println(project);
        }
        System.out.println("done");
    }
    public static void publishProject(String gitPath,String libPath) throws IOException
    {
        System.out.println("publish project");

        String gp_path=libPath+"\\global_planner";
        ArrayList<String> gp_files=getLibFiles(gp_path);
        String slam_path=libPath+"\\slam";
        ArrayList<String> slam_files=getLibFiles(slam_path);


        System.setProperty("com.mchange.v2.log.MLog", "com.mchange.v2.log.FallbackMLog");
        System.setProperty("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL", "WARNING");

        //初始化操作redis的工具类
        RedisOperatorUtil redisUtil = new RedisOperatorUtil("116.62.140.19", "growningai");
        //初始化操作数据库的工具类
        Operator<Project> projectOperator = new Operator<>("projectService");
        String result=null;
        int i=1;
        //从redis获取项目的信息
        while ((result= redisUtil.subscribe())!=null){
            //解析json成对象
            Project project = JSONObject.parseObject(result, Project.class);

            //分析项目
            String typeResult = null;
            System.out.println(project.getPath());
            File f=new File(project.getPath());
            //System.out.println("——"+f);
            if(f.isDirectory()) {

                File src = new File(f.toString() + "\\src");
                File[] srcs = src.listFiles();

                float gp_sim = 0;
                float slam_sim = 0;

                int filecount = 0;
                for (File s : srcs) {
                    float gp_similarity = 0;
                    float slam_similarity = 0;
                    int gp_filecount = 0;
                    int slam_filecount = 0;
                    if (s.getPath().endsWith(".cpp")) {
                        filecount++;
                        System.out.println("—— ——" + s);
                        for (String gp_file : gp_files) {
                            float sim = compareSingleCpp(gp_file, s.getPath());
                            gp_similarity += sim;
                            System.gc();
                            Runtime.getRuntime().gc();
                            gp_filecount++;
                            //System.out.println(sim);
                        }

                        for (String slam_file : slam_files) {
                            float sim = compareSingleCpp(slam_file, s.getPath());
                            slam_similarity += sim;
                            System.gc();
                            Runtime.getRuntime().gc();
                            slam_filecount++;
                        }
                        gp_sim += gp_similarity / gp_filecount;
                        slam_sim += slam_similarity / gp_filecount;
                        System.out.println("File:" + s.getPath());
                        System.out.println("global_planner_similarity:" + gp_similarity / gp_filecount);
                        System.out.println("slam_similarity:" + slam_similarity / slam_filecount);
                        if(gp_similarity / gp_filecount>slam_similarity / slam_filecount)
                        {
                            typeResult="global_planner";
                        }
                        else
                        {
                            typeResult="slam";
                        }
                    }

                }
                System.out.println("~Project:" + f.getPath());
                System.out.println("~global_planner_similarity:" + gp_sim / filecount);
                System.out.println("~slam_similarity:" + slam_sim / filecount);
            }
            else if(f.isFile()) {
                //System.out.println("——"+f);
                TreeProcessor tp = new TreeProcessor();



                //
                float gp_similarity = 0;
                float slam_similarity = 0;
                int gp_filecount = 0;
                int slam_filecount = 0;


                String code1 = readFromTextFile(f.getPath());
                Tree tree1 = getMyTreeFromCode(code1);
                StringBuffer s1 = new StringBuffer();
                StringBuffer lessEncode1 = tp.lessEncode(tree1, s1);
                for (String gp_file : gp_files) {
                    String code = readFromTextFile(gp_file);
                    Tree tree2 = getMyTreeFromCode(code);
                    StringBuffer s2 = new StringBuffer();
                    StringBuffer lessEncode2 = tp.lessEncode(tree2, s2);
                    System.out.println("compare file:\t" + f.getPath() + "\tand\t" + gp_file);
                    float sim = levenshtein(lessEncode1.toString(), lessEncode2.toString());
                    gp_similarity += sim;
                    System.gc();
                    Runtime.getRuntime().gc();
                    gp_filecount++;
                }
                for (String slam_file : slam_files) {
                    String code = readFromTextFile(slam_file);
                    Tree tree2 = getMyTreeFromCode(code);
                    StringBuffer s2 = new StringBuffer();
                    StringBuffer lessEncode2 = tp.lessEncode(tree2, s2);
                    System.out.println("compare file:\t" + f.getPath() + "\tand\t" + slam_file);
                    float sim = levenshtein(lessEncode1.toString(), lessEncode2.toString());
                    slam_similarity += sim;
                    System.gc();
                    Runtime.getRuntime().gc();
                    slam_filecount++;
                }
                System.gc();
                Runtime.getRuntime().gc();
                System.out.println("~File:" + f.getPath());
                System.out.println("~global_planner_similarity:" + gp_similarity / gp_filecount);
                System.out.println("~slam_similarity:" + slam_similarity / slam_filecount);
                if(gp_similarity / gp_filecount>slam_similarity / slam_filecount)
                {
                    typeResult="global_planner";
                }
                else
                {
                    typeResult="slam";
                }
                System.out.println();
            }

            //设置剩余的属性值
            String[] sp ;
            sp=f.getPath().split("\\\\");
            String projectName=sp[sp.length-1];
            project.setName(projectName);
            project.setType(typeResult);

            //保存项目到数据库
            projectOperator.save(project);
            System.out.println(project);
        }
        System.out.println("done");
    }

    public static void main(String[] args) throws Exception {
        TreeProcessor tp=new TreeProcessor();

        // create a CharStream thatreads from standard input

        String sql4="int getCellRowID(int index,int p)//get the row ID from cell index\n" +
                "  {\n" +
                "     c1=index/width+p;\n" +
                "     ret=index/c1+p;\n" +
                "     return ret;\n" +
                "  }";
        String sql5="int getCellColID(int ind)//get colunm ID from cell index\n" +
                "  {\n" +
                "    return ind%width;\n" +
                "  }";

        String sql6="void RAstarPlannerROS::convertToCoordinate(int index, float& x, float& y)\n" +
                "{\n" +
                "\n" +
                "  x = getCellColID(index) * resolution;\n" +
                "\n" +
                "  y = getCellRowID(index,q) * resolution;\n" +
                "\n" +
                "  x = x + originX;\n" +
                "  y = y + originY;\n" +
                "\n" +
                "}";





        ANTLRInputStream input4 = new ANTLRInputStream(sql4);
        CPP14Lexer lexer4 = new CPP14Lexer(input4);
        CommonTokenStream tokens4 = new CommonTokenStream(lexer4);
        CPP14Parser parser4 = new CPP14Parser(tokens4);
        CPP14Parser.TranslationunitContext tree4 = parser4.translationunit();

        ANTLRInputStream input5 = new ANTLRInputStream(sql5);
        CPP14Lexer lexer5 = new CPP14Lexer(input5);
        CommonTokenStream tokens5 = new CommonTokenStream(lexer5);
        CPP14Parser parser5 = new CPP14Parser(tokens5);
        CPP14Parser.TranslationunitContext tree5 = parser5.translationunit();

        ANTLRInputStream input6 = new ANTLRInputStream(sql6);
        CPP14Lexer lexer6 = new CPP14Lexer(input6);
        CommonTokenStream tokens6 = new CommonTokenStream(lexer6);
        CPP14Parser parser6 = new CPP14Parser(tokens6);
        CPP14Parser.TranslationunitContext tree6 = parser6.translationunit();



        tree4.removeLastChild();
        System.out.println(tree4.getText());

        Tree myTree4=new Tree(tp.getRuleName(tree4,parser4));
        tp.convertTree(tree4,parser4,myTree4);


        //modify Interface
        ArrayList<String> rep=new ArrayList<>();
        rep.add("x");
        rep.add("y");
        //modifyInterface(myTree4,rep);

        //publishProject("H://GIT","H://lib");

        //compare code
        //compareAfterMerge("H://fetch_code","H://lib");

        //compareWithoutMerge("H://fetch_code","H://lib");

        compareGitProject("H://GIT","H://lib");



    }

}